#!/bin/bash

touch Health-examination

echo '服务器内存和磁盘使用情况：' >> Health-examination
echo '----------------------------------' >> Health-examination
free -h >> Health-examination
echo '------------------' >> Health-examination
df -h >> Health-examination
echo '----------------------------------end' >> Health-examination

echo '服务器CPU情况：' >> Health-examination
echo '----------------------------------' >> Health-examination
uptime >> Health-examination
echo '----------------------------------end' >> Health-examination

echo '数据库连接数情况：' >> Health-examination
echo '----------------------------------' >> Health-examination
echo '曾经的最大连接数：'`mysql -uroot -pxjjy1981123\!\@\# -h103.235.171.109 -e"show status like '%connect%'" 2> /dev/null |grep Max_used_connections|grep -v time|awk '{print $2}'` >> Health-examination
echo '允许的最大连接数：'`mysql -uroot -pxjjy1981123\!\@\# -h103.235.171.109 -e"show variables like '%connect%'" 2> /dev/null |grep max_connections|awk '{print $2}'` >> Health-examination 2> /dev/null
echo '----------------------------------end' >> Health-examination

echo '数据空间占用情况：' >> Health-examination
echo '----------------------------------' >> Health-examination
echo '数据库数据目录占用的空间：'`du /home/sqldata/data/ -h|grep /$|awk '{print $1}'` >> Health-examination
echo '----------------------------------end' >> Health-examination

echo '分成服务和过程执行情况：' >> Health-examination
echo '----------------------------------' >> Health-examination
mysql -uroot -pxjjy1981123\!\@\# -h103.235.171.109 -e'SELECT TIMEDIFF(NOW(),datetime) as delay_time from logdb.maxbh' 2> /dev/null >> Health-examination
echo '----------------------------------end' >> Health-examination

echo '游戏日志写入情况：' >> Health-examination
echo '----------------------------------' >> Health-examination
mysql -uroot -pxjjy1981123\!\@\# -h103.235.171.109 -e'SELECT TIMEDIFF(NOW(),update_date) from logdb.game_record ORDER BY update_date DESC LIMIT 1' 2> /dev/null >> Health-examination
echo '----------------------------------end' >> Health-examination

#echo '数据库服务器锁争用情况：' >> Health-examination
#echo '----------------------------------' >> Health-examination
#mysql -uroot -pxjjy1981123\!\@\# -h103.235.171.109 -e'SHOW ENGINE INNODB STATUS\G' >> Health-examination 2> /dev/null
#echo '----------------------------------end' >> Health-examination

echo '数据备份执行情况：' >> Health-examination
echo '----------------------------------' >> Health-examination
echo '一致性热备文件' >> Health-examination
cd /home/tank/backup
ls -lh *.gz|awk '{print $5"\t"$9}' >> /root/Health-examination
cd /root
echo '----------------------------------end' >> Health-examination

mail -s "TIE:Health examination_`date +%F-%T`" icquu@126.com < /root/Health-examination

rm -f /root/Health-examination
